<template>
	<view>
		<view class="list">
			<view class="item" v-for="(t,i) in list" :key="i">
				<view class="img-box">
					<image :src="t.avatar" mode="widthFix" class="img"></image>
				</view>
				<view class="txts">
					<view class="name">
						<text>{{t.nickname}}</text>
					</view>
					<view class="cont">
						<text>{{t.content}}</text>
					</view>
				</view>
				<view class="btn" @click="chat(t)">
					<text>去聊天</text>
				</view>
			</view>
		</view>
		<view class="none-txt">
			<text>暂无更多消息</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list:[],
				page:1
			};
		},
		onLoad() {
			this.systemIsRead()
			this.getList();
		},
		onReachBottom() {
			this.getList();
		},
		methods:{
			systemIsRead(){
				this.$utils.postrequest("/api/message/systemIsRead", {}, res => {
					if (res.code === 200) {
						// console.log(res)
					} else {
						// console.log(res)
					}
				})	
			},
			chat(t) {
				this.$checkIsVip().then(res => {
					if (res) {
						this.toChat(t)
					} else {
						uni.showModal({
							content: "开通会员即可私聊",
							cancelText: "取消",
							confirmText: "去开通",
							success: res => {
								if (res.confirm) {
									uni.navigateTo({
										url: "/pages/my/vipCenter/vipCenter"
									})
								}
							}
						})
					}
				})
			},
			toChat(t) {
				this.$store.commit('createConversationActive', {
					type: "C2C",
					data: t.user_id
				})
				let userInfo = t
				userInfo.id = t.user_id;
				userInfo.userID = t.user_id;
				// console.log(userInfo)
				uni.setStorageSync('chooseUser', userInfo);
				uni.navigateTo({
					url: '/pages/tim/room'
				})
			},
			getList(){
				this.$utils.postrequest("/api/message/systemList", {
					page:this.page
				}, res => {
					if (res.code === 200) {
						this.list = this.list.concat(res.data);
						this.page++;
					} else {
						// console.log(res)
					}
				})
			}
		}
	}
</script>

<style lang="scss">
.list{
	width: 100%;
	box-sizing: border-box;
	padding: 0 30rpx;
	.item{
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 24rpx 0;
		border-bottom: 1px solid #F6F5FA;
		.img-box{
			width: 102rpx;
			height: 102rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			overflow: hidden;
			border-radius: 50%;
			.img{
				width: 100%;
			}
		}
		.txts{
			width: 436rpx;
			.name{
				font-size: 32rpx;
				font-family: PingFang SC;
				line-height: 32rpx;
				color: #424242;
				margin-bottom: 18rpx;
			}
			.cont{
				font-size: 24rpx;
				font-family: PingFang SC;
				color: #333333;
				line-height: 24rpx;
			}
		}
		.btn{
			width: 106rpx;
			height: 52rpx;
			background: linear-gradient(138deg, #8478FE, #5B47FF);
			border-radius: 10rpx;
			text-align: center;
			font-size: 26rpx;
			font-family: PingFang SC;
			color: #FFFFFF;
			line-height: 52rpx;
		}
	}
}
.none-txt{text-align: center;color: #999;font-size: 26rpx;padding: 20rpx 0;}
</style>
